import { createRouter, createWebHistory } from 'vue-router'
import UserManagement from '../views/UserManagement.vue'
import Login from '../login.vue'
import UserRootManage from '../views/UserRootManage.vue'
const routes = [
 
  {
    path: '/usermanagement',
    name: 'usermanagement',
    component: UserManagement,
    meta: {
      title: '用户管理',
      icon: 'user'
    }
  },  {
    path: '/userrootmanage',
    name: 'userrootmanage',
    component: UserRootManage,
    meta: {
      title: '权限管理',
      icon: 'user'
    }
  },
  {
    path: '/',
    name: 'login',
    component: Login,
    meta: {
      title: '登录',
      icon: 'user'
    }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})
/**
 * 路由守卫，防止未登录用户 进入主页
 *
 */
router.beforeEach((to,from,next)=>{
	if(to.fullPath!='/'){
		if(localStorage.getItem("uname")==null || localStorage.getItem("token")==null){//用户未登录，要求登录
			next("/")
		}else{
			next()
		}
	}else{
		next()
	}
})
export default router